<?php
/**
 * 后台首页
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: IndexController.class.php v1.0 2014-06-12 17:27:03 $
 */
namespace Admin\Controller;
class IndexController extends CommonController {
    public function index(){
        $admin_db      = D('Admin', "Service");
        $userid   = getUserId();
        $userInfo = $admin_db->getSysUserInfo($userid, true);    //获取用户基本信息
        
        //$sysinfo = \Admin\Plugin\SysinfoPlugin::getinfo();
        $os = explode(' ', php_uname());
        //网络使用状况
        $net_state = null;
        /*if ($sysinfo['sysReShow'] == 'show' && false !== ($strs = @file("/proc/net/dev"))){
                for ($i = 2; $i < count($strs); $i++ ){
                        preg_match_all( "/([^\s]+):[\s]{0,}(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/", $strs[$i], $info );
                        $net_state.="{$info[1][0]} : 已接收 : <font color=\"#CC0000\"><span id=\"NetInput{$i}\">".$sysinfo['NetInput'.$i]."</span></font> GB &nbsp;&nbsp;&nbsp;&nbsp;已发送 : <font color=\"#CC0000\"><span id=\"NetOut{$i}\">".$sysinfo['NetOut'.$i]."</span></font> GB <br />";
                }
        }*/
        //var_dump($userInfo);die;
        $this->assign('userInfo', $userInfo);
        //$this->assign('sysinfo',$sysinfo);
        $this->assign('os',$os);
        $this->assign('net_state',$net_state);
        $this->display();
    }
    
    /**
     * 编辑个人密码
     * @return
     */
    public function editPassword() {
        $admin = $_SESSION['current_account'];
        $this->assign('admin', $admin);
        $this->display('edit_password');
    }
    
    /**
     * 更新个人密码
     * @return
     */
    public function updatePassword() {
        $postAdmin = I('post.admin');
        if (!isArrayAndNotEmpty($postAdmin)) {
            return $this->errorReturn('无效的操作！');
        }
        
        $admin = I("session.current_account");
        $admin['pwd'] = $postAdmin['pwd'];
        $admin['cfm_pwd'] = $postAdmin['cfm_pwd'];

        //var_dump($admin);die;
        $result = D('Admin', 'Service')->updateSysUser($admin);
        if (!$result['status']) {
            return $this->errorReturn($result['data']['error']);
        }

        return $this->successReturn('修改密码成功！');
    }
    
    /**
     * 编辑站点信息
     * @return
     */
    public function siteEdit() {
        $title = C('SITE_TITLE');
        $keyword = C('SITE_KEYWORD');
        $description = C('SITE_DESCRIPTION');

        $this->assign('title', $title);
        $this->assign('keyword', $keyword);
        $this->assign('description', $description);
        $this->display('site_edit');
    }
    
    /**
     * 更新站点信息
     * @return
     */
    public function siteUpdate() {
        $site = I("post.site");
        if (!isArrayAndNotEmpty($site)) {
            return $this->errorReturn('无效的操作！');
        }

        $confName = 'web_config';

        $conf = fast_cache($confName, '', YDCMS_DATA);
        $conf['SITE_TITLE'] = $site['title'];
        $conf['SITE_KEYWORD'] = $site['keyword'];
        $conf['SITE_DESCRIPTION'] = $site['description'];

        if (false === fast_cache($confName, $conf, YDCMS_DATA)) {
            return $this->errorReturn('站点信息更新失败！');
        }

        return $this->successReturn('站点信息更新成功！');
    }
}